﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;

namespace CalService.Model
{
    [DataContract (IsReference=true)]
    public class User
    {
        private string _userName;
        private string _passWord;
        private int _pkID = 0;

        [DataMember]
        public string Username
        {
            get { return _userName; }
            set { _userName = value; }
        }//end username field

        [DataMember]
        public string Password
        {
            get { return _passWord; }
            set { _passWord = value; }
        }//end password

        [DataMember]
        public int PKID
        {
            get { return _pkID; }
            set { _pkID = value; }
        }//end PKID

        //constructor with parameters
        public User(string UserName, string PassWord)
        {
            DalServiceRef.IDalService sr = new DalServiceRef.DalServiceClient();

            DataTable dt = sr.GetLogin(UserName, PassWord);
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow r in dt.Rows)
                {
                    _pkID = Convert.ToInt32(r["pkID"].ToString());
                    this.Username = r["OwnerName"].ToString();
                }
            }
            else
                _pkID = 0;
        }
        public User()
        {
            _pkID = 0;
            this.Username = null;
            this.Password = null;
        }
    }
}